package fy.bean;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;


import fy.util.DBUtil;

//类名
public class DwgzBean {
	//属性（成员变量）
	private int id;
	private String category;
	private String title;
	private String content;
	private int homepage;
	private String author;
	private Date time;
	private String source;
	private String categoryname;
	private String picture;
	private int puton;
	
	PreparedStatement statement=null;
	ResultSet rs = null;
	Connection connection = null;
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getCategory() {
		return category;
	}
	public void setCategory(String category) {
		this.category = category;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public int getHomepage() {
		return homepage;
	}
	public void setHomepage(int homepage) {
		this.homepage = homepage;
	}
	public String getAuthor() {
		return author;
	}
	public void setAuthor(String author) {
		this.author = author;
	}
	public Date getTime() {
		return time;
	}
	public void setTime(Date time) {
		this.time = time;
	}
	public String getSource() {
		return source;
	}
	public void setSource(String source) {
		this.source = source;
	}
	public String getPicture() {
		return picture;
	}
	public void setPicture(String picture) {
		this.picture = picture;
	}
	public int getPuton() {
		return puton;
	}
	public void setPuton(int puton) {
		this.puton = puton;
	}
		public String getCategoryname() {
		return categoryname;
	}
	public void setCategoryname(String categoryname) {
		this.categoryname = categoryname;
	}
		//查询全部内容
		public List<DwgzBean> findAll() {
			List<DwgzBean> list = new ArrayList<DwgzBean>();
			DBUtil dbUtil = new DBUtil();
			String sql = "select * from dwgz where puton=1 order by time desc";
			connection = dbUtil.geConnection();
			try {
				statement = connection.prepareStatement(sql);
				rs = statement.executeQuery();
				while(rs.next()) {
					DwgzBean dwgzBean = new DwgzBean();
					dwgzBean.setId(rs.getInt("id"));
					dwgzBean.setTitle(rs.getString("title"));
					dwgzBean.setCategory(rs.getString("Category"));
					dwgzBean.setContent(rs.getString("content"));
					dwgzBean.setTime(rs.getDate("time"));
					dwgzBean.setAuthor(rs.getString("author"));
					dwgzBean.setHomepage(rs.getInt("homepage"));
					dwgzBean.setPicture(rs.getString("picture"));
					dwgzBean.setSource(rs.getString("source"));
					dwgzBean.setCategoryname(rs.getString("categoryname"));
					dwgzBean.setPuton(rs.getInt("puton"));

					list.add(dwgzBean);
				}
				
			} catch (SQLException e) {
				e.printStackTrace();
			}finally {
				if (rs != null) {
					try {
						rs.close();
					} catch (SQLException e) {
						e.printStackTrace();
					}
				}
				if (statement != null) {
					try {
						statement.close();
					} catch (SQLException e) {
						e.printStackTrace();
					}
				}
				if(connection != null) {
					try {
						connection.close();
					} catch (SQLException e) {
						e.printStackTrace();
					}
				}
				dbUtil.close();
			}
			return list;
			
		}

		//通过ID查找
				public DwgzBean findDwgzById(int id) {
					
					DBUtil dbUtil = new DBUtil();
					connection = dbUtil.geConnection();
					DwgzBean dwgzBean = new DwgzBean();
					try {
						String sql = "select * from dwgz where id = ?  order by time desc";
						statement = connection.prepareStatement(sql);
						statement.setInt(1, id);
						rs = statement.executeQuery();
						
						if(rs.next()) {
							dwgzBean.setId(rs.getInt("id"));
							dwgzBean.setTitle(rs.getString("title"));
							dwgzBean.setCategory(rs.getString("category"));
							dwgzBean.setContent(rs.getString("content"));
							dwgzBean.setTime(rs.getDate("time"));
							dwgzBean.setAuthor(rs.getString("author"));
							dwgzBean.setHomepage(rs.getInt("homepage"));
							dwgzBean.setPicture(rs.getString("picture"));
							dwgzBean.setSource(rs.getString("source"));
							dwgzBean.setCategoryname(rs.getString("categoryname"));
							dwgzBean.setPuton(rs.getInt("puton"));

						}
						
					} catch (SQLException e) {
						e.printStackTrace();
					}finally {
						if (rs != null) {
							try {
								rs.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						if (statement != null) {
							try {
								statement.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						if(connection != null) {
							try {
								connection.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						dbUtil.close();
					}

					return dwgzBean;
					
				}
		
				//通过类别查找
				public List<DwgzBean> finddwgzByLb(String lbString) {
					List<DwgzBean> list = new ArrayList<DwgzBean>();
					DBUtil dbUtil = new DBUtil();
					connection = dbUtil.geConnection();
					String sql = "select * from dwgz where category =? and puton = 1 order by time desc";
					try {
						statement = connection.prepareStatement(sql);
						statement.setString(1, lbString);
						rs = statement.executeQuery();
						while(rs.next()) {
							DwgzBean dwgzBean = new DwgzBean();
							dwgzBean.setId(rs.getInt("id"));
							dwgzBean.setTitle(rs.getString("title"));
							dwgzBean.setCategory(rs.getString("Category"));
							dwgzBean.setContent(rs.getString("content"));
							dwgzBean.setTime(rs.getDate("time"));
							dwgzBean.setAuthor(rs.getString("author"));
							dwgzBean.setHomepage(rs.getInt("homepage"));
							dwgzBean.setPicture(rs.getString("picture"));
							dwgzBean.setSource(rs.getString("source"));
							dwgzBean.setCategoryname(rs.getString("categoryname"));
							dwgzBean.setPuton(rs.getInt("puton"));

							list.add(dwgzBean);
						}


					} catch (SQLException e) {
						e.printStackTrace();
					}finally {
						if (rs != null) {
							try {
								rs.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						if (statement != null) {
							try {
								statement.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						if(connection != null) {
							try {
								connection.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						dbUtil.close();
					}
					return list;
					
				}
		
				//增加页面内容
				public boolean doAdd(String category,String title,String content,Integer homepage,String picture,String author,String source,String txtDate,String categoryname,int puton) {
					boolean add = false;
					DBUtil dbUtil = new DBUtil();
					connection = dbUtil.geConnection();
					//String sql = "select password from admin where username = " + username + "'";
					String sql = "insert into dwgz(category,title,content,homepage,picture,author,source,time,categoryname,puton) values(?,?,?,?,?,?,?,?,?,?)";
					
				  try {		
					  PreparedStatement statement = connection.prepareStatement(sql);
						statement.setString(1, category);
						statement.setString(2, title);
						statement.setString(3, content);
						statement.setInt(4, homepage);
						statement.setString(5, picture);
						statement.setString(6, author);
						statement.setString(7, source);
						statement.setString(8, txtDate);
						statement.setString(9, categoryname);
						statement.setInt(10, puton);
						System.out.println(add);
						int i = statement.executeUpdate();
						if (i>0) {
							add = true;
						}
							
					} catch (SQLException e) {
						e.printStackTrace();
					}finally {
						if (rs != null) {
							try {
								rs.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						if (statement != null) {
							try {
								statement.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						if(connection != null) {
							try {
								connection.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						dbUtil.close();
					}
					return add;
					
				}
				
				//修改内容
				public boolean doUpdata(String category,String title,String content,Integer homepage,String picture,String author,String source,String txtDate,String categoryname,int puton,int id) {
					boolean updata = false;
					DBUtil dbUtil = new DBUtil();
					connection = dbUtil.geConnection();
					//String sql = "select password from admin where username = " + username + "'";
					String sql = "update dwgz set category =?,title =?,content =?,homepage =?,picture =?,author =?,source=?,time=?,categoryname=?,puton=? where id =?";
					try {
						PreparedStatement statement = connection.prepareStatement(sql);
						statement.setString(1, category);
						statement.setString(2, title);
						statement.setString(3, content);
						statement.setInt(4, homepage);
						statement.setString(5, picture);
						statement.setString(6, author);
						statement.setString(7, source);
						statement.setString(8, txtDate);
						statement.setString(9, categoryname);
						statement.setInt(10, puton);
						statement.setInt(11, id);
						System.out.println(updata);
						int i = statement.executeUpdate();
						if (i>0) {
							updata = true;
						}
							
					} catch (SQLException e) {
						e.printStackTrace();
					}finally {
						if (rs != null) {
							try {
								rs.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						if (statement != null) {
							try {
								statement.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						if(connection != null) {
							try {
								connection.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						dbUtil.close();
					}
					return updata;
					
				}
				
				
				//删除内容
				public boolean doDel(int id) {
					boolean del = false;
					DBUtil dbUtil = new DBUtil();
					connection = dbUtil.geConnection();
					String sql = "delete from  dwgz where id =?";
					//String sql = "insert into sfgk(v1,v2) values(?,getdate());";
				    //String sql = "insert into sfgk(category,title,source,content,author,id) values(?,?,?,?,?,?)";
					
				  try {		
					  PreparedStatement statement = connection.prepareStatement(sql);
				
						statement.setInt(1, id);
						int i = statement.executeUpdate();
						if (i>0) {
							del = true;
						}
							
					} catch (SQLException e) {
						e.printStackTrace();
					}finally {
						if (rs != null) {
							try {
								rs.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						if (statement != null) {
							try {
								statement.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						if(connection != null) {
							try {
								connection.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						dbUtil.close();
					}
					return del;
					
				}
				
				//放在首页的方法
				public List<DwgzBean> findOnindex() {
					List<DwgzBean> list = new ArrayList<DwgzBean>();
					DBUtil dbUtil = new DBUtil();
					String sql = "select * from dwgz where homepage=1 and puton=1 order by time desc ";
					connection = dbUtil.geConnection();
					try {
						statement = connection.prepareStatement(sql);
						rs = statement.executeQuery();
						while(rs.next()) {
							DwgzBean dwgzBean = new DwgzBean();
							dwgzBean.setId(rs.getInt("id"));
							dwgzBean.setTitle(rs.getString("title"));
							dwgzBean.setCategory(rs.getString("Category"));
							dwgzBean.setContent(rs.getString("content"));
							dwgzBean.setTime(rs.getDate("time"));
							dwgzBean.setAuthor(rs.getString("author"));
							dwgzBean.setHomepage(rs.getInt("homepage"));
							dwgzBean.setPicture(rs.getString("picture"));
							dwgzBean.setSource(rs.getString("source"));
							dwgzBean.setCategoryname(rs.getString("categoryname"));
							list.add(dwgzBean);
						}
						
					} catch (SQLException e) {
						e.printStackTrace();
					}finally {
						if (rs != null) {
							try {
								rs.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						if (statement != null) {
							try {
								statement.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						if(connection != null) {
							try {
								connection.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						dbUtil.close();
					}
					return list;
					
				}
				
				//通过时间排序
				public List<DwgzBean> findAllByLbForPX(String lbString) {
					System.out.println("run findAllByLb " + lbString);
					List<DwgzBean> list = new ArrayList<DwgzBean>();
					DBUtil dbUtil = new DBUtil();
					connection = dbUtil.geConnection();
					String sql = "select * from dwgz where category = ? and puton=1 order by time desc";
					try {
						statement = connection.prepareStatement(sql);
						statement.setString(1, lbString);
						rs = statement.executeQuery();
						while (rs.next()) {
							DwgzBean dwgzBean = new DwgzBean();
							dwgzBean.setId(rs.getInt("id"));
							dwgzBean.setTitle(rs.getString("title"));
							dwgzBean.setCategory(rs.getString("Category"));
							dwgzBean.setContent(rs.getString("content"));
							dwgzBean.setTime(rs.getDate("time"));
							dwgzBean.setAuthor(rs.getString("author"));
							dwgzBean.setHomepage(rs.getInt("homepage"));
							dwgzBean.setPicture(rs.getString("picture"));
							dwgzBean.setSource(rs.getString("source"));
							dwgzBean.setCategoryname(rs.getString("categoryname"));
							list.add(dwgzBean);
							System.out.println("findAllByLb  " + dwgzBean);
						}
						
					} catch (Exception e) {
						e.printStackTrace();
					}finally {
						if (rs != null) {
							try {
								rs.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						if (statement != null) {
							try {
								statement.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						if(connection != null) {
							try {
								connection.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						dbUtil.close();
					}
					return list;
					
				}
				
				//前端类别查找
				public List<DwgzBean> findAllByLb(String lbString) {
					List<DwgzBean> list = new ArrayList<DwgzBean>();
					DBUtil dbUtil = new DBUtil();
					connection = dbUtil.geConnection();
					String sql = "select * from dwgz where category =? and puton=1 order by time desc";
					try {
						statement = connection.prepareStatement(sql);
						statement.setString(1, lbString);
						rs = statement.executeQuery();
						while(rs.next()) {
							DwgzBean dwgzBean = new DwgzBean(); 
							dwgzBean.setCategory(rs.getString("category"));
							dwgzBean.setId(rs.getInt("id"));
							dwgzBean.setTitle(rs.getString("title"));
							dwgzBean.setContent(rs.getString("content"));
							dwgzBean.setAuthor(rs.getString("author"));
							dwgzBean.setSource(rs.getString("source"));
							dwgzBean.setTime(rs.getDate("time"));
							dwgzBean.setCategoryname(rs.getString("categoryname"));
							dwgzBean.setPicture(rs.getString("picture"));
							System.out.println(dwgzBean.getPicture());
							dwgzBean.setPuton(rs.getInt("puton"));
							list.add(dwgzBean);
						}
						
					} catch (SQLException e) {
						e.printStackTrace();
					}finally {
						if (rs != null) {
							try {
								rs.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						if (statement != null) {
							try {
								statement.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						if(connection != null) {
							try {
								connection.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						dbUtil.close();
					}
					return list;
					
				}

				//后端页面通过类别查找
				public List<DwgzBean> findbackByLb(String lbString) {
					List<DwgzBean> list = new ArrayList<DwgzBean>();
					DBUtil dbUtil = new DBUtil();
					connection = dbUtil.geConnection();
					String sql = "select * from dwgz where category =? order by time desc";
					try {
						statement = connection.prepareStatement(sql);
						statement.setString(1, lbString);
						rs = statement.executeQuery();
						while(rs.next()) {
							DwgzBean dwgzBean = new DwgzBean();
							dwgzBean.setCategory(rs.getString("category"));
							dwgzBean.setId(rs.getInt("id"));
							dwgzBean.setTitle(rs.getString("title"));
							dwgzBean.setContent(rs.getString("content"));
							dwgzBean.setAuthor(rs.getString("author"));
							dwgzBean.setSource(rs.getString("source"));
							dwgzBean.setTime(rs.getDate("time"));
							dwgzBean.setCategoryname(rs.getString("categoryname"));
							dwgzBean.setPicture(rs.getString("picture"));
							System.out.println(dwgzBean.getPicture());
							list.add(dwgzBean);
						}
						
					} catch (SQLException e) {
						e.printStackTrace();
					}finally {
						if (rs != null) {
							try {
								rs.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						if (statement != null) {
							try {
								statement.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						if(connection != null) {
							try {
								connection.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						dbUtil.close();
					}
					return list;
					
				}
				
				
				//总数查询
				public int findCountByLb(String lbString) {
					DBUtil dbUtil = new DBUtil();
					connection = dbUtil.geConnection();
					int count = 0;
					String sql = "select count(*) totalCount from dwgz where category =? and puton=1 order by time desc";
					try {
						statement = connection.prepareStatement(sql);
						statement.setString(1, lbString);
						rs = statement.executeQuery();
						if (rs.next()) {
							count=rs.getInt("totalCount");
						}
						
					} catch (SQLException e) {
						e.printStackTrace();
					}finally {
						if (rs != null) {
							try {
								rs.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						if (statement != null) {
							try {
								statement.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						if(connection != null) {
							try {
								connection.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						dbUtil.close();
					}
					return count;
					
				}


				//分页
				public List<DwgzBean> findAllByLbForFY(String lbString,Page page) {
					List<DwgzBean> list = new ArrayList<DwgzBean>();
					DBUtil dbUtil = new DBUtil();
					connection = dbUtil.geConnection();
					String sql = "select * from dwgz where category =? and puton=1 order by time desc limit ?,? ";
					try {
						statement = connection.prepareStatement(sql);
						statement.setString(1, lbString);
						statement.setInt(2, page.getBeginIndex());
						statement.setInt(3, page.getEveryPage());
						rs = statement.executeQuery();
						while(rs.next()) {
							DwgzBean dwgzBean = new DwgzBean();
							dwgzBean.setId(rs.getInt("id"));
							dwgzBean.setTitle(rs.getString("title"));
							dwgzBean.setCategory(rs.getString("Category"));
							dwgzBean.setContent(rs.getString("content"));
							dwgzBean.setTime(rs.getDate("time"));
							dwgzBean.setAuthor(rs.getString("author"));
							dwgzBean.setHomepage(rs.getInt("homepage"));
							dwgzBean.setPicture(rs.getString("picture"));
							dwgzBean.setSource(rs.getString("source"));
							dwgzBean.setCategoryname(rs.getString("categoryname"));
							list.add(dwgzBean);
						}
						
					} catch (SQLException e) {
						e.printStackTrace();
					}finally {
						if (rs != null) {
							try {
								rs.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						if (statement != null) {
							try {
								statement.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						if(connection != null) {
							try {
								connection.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						dbUtil.close();
					}
					return list;
					
				}
				//查找上一页的ID
				public DwgzBean findPreNewsById(List<DwgzBean> listDwgzBean, int id) {
					DwgzBean dwgzBean = null;
					for(int i=0;i<listDwgzBean.size();i++) {
						if(id == listDwgzBean.get(i).getId()&&i!=0) {
							dwgzBean = listDwgzBean.get(i-1);
							return dwgzBean;
						}
					}
					return dwgzBean;
					 
					}

            //查找下一页的ID
				public DwgzBean findNextNewsById(List<DwgzBean> listDwgzBean,int id) {
					DwgzBean dwgzBean = null;
					for(int i=0;i<listDwgzBean.size();i++) {
						if(id == listDwgzBean.get(i).getId()&&i+1<listDwgzBean.size()) {
							dwgzBean = listDwgzBean.get(i+1);
							return dwgzBean;
						}
					}
					return dwgzBean;
					 
					 
					}
				
				public DwgzBean findPreNewsById(int id) {
					System.out.println("run findNewsByid  nad ib");
					DBUtil dbUtil = new DBUtil();
					connection = dbUtil.geConnection();
					DwgzBean dwgzBean = new DwgzBean();
					String sql = "select * from dwgz where id < ? and puton=1 order by id desc limit 1 ";
					try {
						statement = connection.prepareStatement(sql);
						statement.setInt(1, id);
						System.out.println(sql);
						rs = statement.executeQuery();
						System.out.println(sql);
						
						if(rs.next()) {
							dwgzBean.setId(rs.getInt("id"));
							dwgzBean.setTitle(rs.getString("title"));
							dwgzBean.setContent(rs.getString("content"));
							dwgzBean.setTime(rs.getDate("time"));
							dwgzBean.setAuthor(rs.getString("author"));
							dwgzBean.setSource(rs.getString("source"));
							dwgzBean.setPicture(rs.getString("picture"));
							dwgzBean.setCategoryname(rs.getString("categoryname"));
							dwgzBean.setPuton(rs.getInt("puton"));
							
						}
						
					} catch (SQLException e) {
						e.printStackTrace();
					}finally {
						if (rs != null) {
							try {
								rs.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						if (statement != null) {
							try {
								statement.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						if(connection != null) {
							try {
								connection.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						dbUtil.close();
					}

					return dwgzBean;
					
				}
				
				
				
				
				public DwgzBean findNextNewsById( int id) {
					
					DBUtil dbUtil = new DBUtil();
					connection = dbUtil.geConnection();
					DwgzBean dwgzBean = new DwgzBean();
					String sql = "select * from dwgz where id > ? and homepage=1 and puton=1 order by id asc limit 1 ";
					try {
						
						statement = connection.prepareStatement(sql);
						statement.setInt(1, id);
						System.out.println(sql);
						rs = statement.executeQuery();
						System.out.println(sql);
						if(rs.next()) {
							dwgzBean.setId(rs.getInt("id"));
							dwgzBean.setTitle(rs.getString("title"));
							dwgzBean.setContent(rs.getString("content"));
							dwgzBean.setTime(rs.getDate("time"));
							dwgzBean.setAuthor(rs.getString("author"));
							dwgzBean.setSource(rs.getString("source"));
							dwgzBean.setPicture(rs.getString("picture"));
							dwgzBean.setCategoryname(rs.getString("categoryname"));
							dwgzBean.setPuton(rs.getInt("puton"));
							System.out.println(dwgzBean.getPicture());
						}
						
					} catch (SQLException e) {
						e.printStackTrace();
					}finally {
						if (rs != null) {
							try {
								rs.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						if (statement != null) {
							try {
								statement.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						if(connection != null) {
							try {
								connection.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						dbUtil.close();
					}

					return dwgzBean;
					
				}
				
				//后端查询总数
				public int findbackCountByLb(String lbString) {
					DBUtil dbUtil = new DBUtil();
					connection = dbUtil.geConnection();
					int count = 0;
					String sql = "select count(*) totalCount from dwgz where category =? ";
					try {
						statement = connection.prepareStatement(sql);
						statement.setString(1, lbString);
						rs = statement.executeQuery();
						if (rs.next()) {
							count=rs.getInt("totalCount");
						}
						
					} catch (SQLException e) {
						e.printStackTrace();
					}finally {
						if (rs != null) {
							try {
								rs.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						if (statement != null) {
							try {
								statement.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						if(connection != null) {
							try {
								connection.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						dbUtil.close();
					}
					return count;
					
				}
				
				
				
				
				
				//后端分页
				public List<DwgzBean> findbackByLbForFY(String lbString,Page page) {
					List<DwgzBean> list = new ArrayList<DwgzBean>();
					DBUtil dbUtil = new DBUtil();
					connection = dbUtil.geConnection();
					String sql = "select * from dwgz where category =? order by time desc limit ?,? ";
					try {
						statement = connection.prepareStatement(sql);
						statement.setString(1, lbString);
						statement.setInt(2, page.getBeginIndex());
						statement.setInt(3, page.getEveryPage());
						rs = statement.executeQuery();
						while(rs.next()) {
							DwgzBean dwgzBean = new DwgzBean();
							dwgzBean.setCategory(rs.getString("category"));
							dwgzBean.setId(rs.getInt("id"));
							dwgzBean.setHomepage(rs.getInt("homepage"));
							dwgzBean.setPuton(rs.getInt("puton"));
							dwgzBean.setTitle(rs.getString("title"));
							dwgzBean.setContent(rs.getString("content"));
							dwgzBean.setAuthor(rs.getString("author"));
							dwgzBean.setSource(rs.getString("source"));
							dwgzBean.setCategoryname(rs.getString("categoryname"));
							dwgzBean.setTime(rs.getDate("time"));
							dwgzBean.setPicture(rs.getString("picture"));
							System.out.println(dwgzBean.getPicture());
							list.add(dwgzBean);
						}
						
					} catch (SQLException e) {
						e.printStackTrace();
					}finally {
						if (rs != null) {
							try {
								rs.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						if (statement != null) {
							try {
								statement.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						if(connection != null) {
							try {
								connection.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						dbUtil.close();
					}
					return list;
					
				}

				//后端模糊查询后总数
				public int findselectCountByLb(String lbString,String tilString) {
					DBUtil dbUtil = new DBUtil();
					connection = dbUtil.geConnection();
					int count = 0;
					String sql = "select count(*) totalCount from dwgz where category =? and concat(id,title,content,category,author,source,time,puton) like ? ";
					try {
						statement = connection.prepareStatement(sql);
						statement.setString(1, lbString);
						statement.setString(2,"%" + tilString + "%");
						rs = statement.executeQuery();
						if (rs.next()) {
							count=rs.getInt("totalCount");
							System.out.print("totalCount :"+count);
						}
						
					} catch (SQLException e) {
						e.printStackTrace();
					}finally {
						if (rs != null) {
							try {
								rs.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						if (statement != null) {
							try {
								statement.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						if(connection != null) {
							try {
								connection.close();
							} catch (SQLException e) {
								e.printStackTrace();
							}
						}
						dbUtil.close();
					}
					return count;
					
				}
				//模糊查询
						 public List<DwgzBean> Proselect(String lbString,String tilString,Page page) {
						    List<DwgzBean> list =new ArrayList<DwgzBean>();
						    DBUtil dbUtil = new DBUtil();
						    connection = dbUtil.geConnection();
						    //String sql = "select * from news";
						    String sql ="select * from dwgz where category =? and concat(id,title,category,content,author,source,time,puton) like ? order by time desc limit ?,?" ;
						    connection = dbUtil.geConnection();
						    try {
						     statement = connection.prepareStatement(sql);
						     statement.setString(1, lbString);
						     statement.setString(2,"%" + tilString + "%");
						     statement.setInt(3, page.getBeginIndex());
						     statement.setInt(4, page.getEveryPage());
						     rs = statement.executeQuery();
						     while(rs.next()) {
						    	 DwgzBean dwgzBean = new DwgzBean();
						    	 dwgzBean.setId(rs.getInt("id"));
						    	 dwgzBean.setTitle(rs.getString("title"));
						    	 dwgzBean.setContent(rs.getString("content"));
						    	 dwgzBean.setCategory(rs.getString("category"));
						    	 dwgzBean.setAuthor(rs.getString("author"));
						    	 dwgzBean.setSource(rs.getString("source"));
						    	 dwgzBean.setTime(rs.getDate("time"));
						   dwgzBean.setPicture(rs.getString("picture"));
						   dwgzBean.setPuton(rs.getInt("puton"));
						      list.add(dwgzBean);
						     }
						     
						    } catch (SQLException e) {
						     e.printStackTrace();
						    }finally {
						     if (rs != null) {
						      try {
						       rs.close();
						      } catch (SQLException e) {
						       e.printStackTrace();
						      }
						     }
						     if (statement != null) {
						      try {
						       statement.close();
						      } catch (SQLException e) {
						       e.printStackTrace();
						      }
						     }
						     if(connection != null) {
						      try {
						       connection.close();
						      } catch (SQLException e) {
						       e.printStackTrace();
						      }
						     }
						     dbUtil.close();
						    }
						    return list;
						    
						   }
				
			
			

				
				
				@Override
				public String toString() {
					return "DwgzBean [id=" + id + ",title="+title+", picture=" + picture + ",category="+ category + ",content="+content+",time="+time+",author="+author+", homepage=" + homepage + ", picture="+picture+",source="+source+",categoryname="+categoryname+",puton="+puton+" ]";
				}

				public static void main(String[] args) {
					
				}

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
}
